package org.etom.impl.ui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Shell;
import org.etom.connector.datatypes.IMoodleModule;
import org.etom.impl.ui.Activator;
import org.etom.impl.ui.common.IconConstants;
import org.etom.impl.ui.views.ViewsMessages;
import org.etom.impl.ui.wizards.DownloadAsWizard;

/**
 * An action class which is responsible for the download
 * of the available module.
 */
public class DownloadAsAction extends Action {
  
  private Shell shell;
  private IMoodleModule moodleModule;
  
  /**
   * Construct a new download action.
   * 
   * @param shell - the shell is used in the wizard
   * @param moodleModule - the module which will be downloaded
   */
  public DownloadAsAction(Shell shell, IMoodleModule moodleModule) {
    this.shell = shell;
    this.moodleModule = moodleModule;
    init();
  }

  /**
   * @see org.eclipse.jface.action.Action#run()
   */
  @Override
  public void run() {
    if (moodleModule == null) return;
    (new DownloadAsWizard(shell, moodleModule)).open();
  }
  
  /*
   * The method initializes the download action.
   */
  private void init() {
    setText(ViewsMessages.Resources_Context_Menu_DownloadAs);
    setImageDescriptor(ImageDescriptor.createFromFile(Activator.class,
        IconConstants.MENU_DOWNLOAD_ICON_PATH));
  }
  
}
